use error_macro::stack_trace_debug;
use snafu::{prelude::*, Location};

use std::io;
use std::path::PathBuf;

#[stack_trace_debug]
#[derive( Snafu)]
enum Error {
    #[snafu(display("ReadConfigurationErr: Unable to read configuration from {}",info))]
    ReadConfigurationErr {
        #[snafu(implicit)]
        location: Location,
        #[snafu(source)]
        error: io::Error,
        info:String
    },

    #[snafu(display("Unable to write result to {}",info))]
    WriteResultErr {
        #[snafu(implicit)]
        location: Location,
        #[snafu(source)]
        error: io::Error,
        info:String
    },
}
use std::fs;

fn main() {
    let output=test3();
    println!("{:#?}",output);
    println!("Hello, world!");
}

fn test()->Result<(),Error>{
    let path = "config2.toml";
    let _ = fs::read_to_string(path).context(ReadConfigurationErrSnafu{info:path.to_owned()} )?;
    Ok(())
}

fn test2()->Result<(),Error>{
    test()?;
    Ok(())
}

fn test3()->Result<(),Error>{
    test2()?;
    Ok(())
}
